home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / ScanImage / ScanImage.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  9.3 KB  |  427 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Cursor;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.MediaTracker;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13. import java.net.MalformedURLException;
  14. import java.net.URL;
  15. import java.net.URLEncoder;
  16.  
  17. public class ScanImage extends Applet implements Runnable, MouseListener {
  18.    private Thread thread;
  19.    private Image image;
  20.    private Image buffer;
  21.    // $FF: renamed from: b java.awt.Graphics
  22.    private Graphics field_0;
  23.    private boolean loaded = false;
  24.    private boolean move = true;
  25.    // $FF: renamed from: on boolean
  26.    private boolean field_1 = true;
  27.    // $FF: renamed from: wi int
  28.    private int field_2;
  29.    // $FF: renamed from: he int
  30.    private int field_3;
  31.    private int wi_im;
  32.    private int he_im;
  33.    private int pause;
  34.    private double phi;
  35.    // $FF: renamed from: X int
  36.    private int field_4;
  37.    // $FF: renamed from: Y int
  38.    private int field_5;
  39.    // $FF: renamed from: r int
  40.    private int field_6;
  41.    private int r_lim = 100;
  42.    private int r_step = 4;
  43.    private String image_string;
  44.    private String statusBarText;
  45.    private AudioClip sound;
  46.    private AudioClip clicSound;
  47.    private AudioClip enterSound;
  48.    private boolean loopSound;
  49.    private String link;
  50.    // $FF: renamed from: fm java.awt.FontMetrics
  51.    private FontMetrics field_7;
  52.    private String enterText;
  53.    private boolean isEnterTextEnabled;
  54.    private int wiEnterText;
  55.    private int enterTextHeight;
  56.    private Color enterTextColor;
  57.  
  58.    public String getAppletInfo() {
  59.       return "Name: ScanImage\r\nAuthor: Taiji Software\r\n";
  60.    }
  61.  
  62.    public ScanImage() {
  63.       this.move = true;
  64.       this.pause = 50;
  65.       this.r_lim = 100;
  66.       this.r_step = 10;
  67.       ((Component)this).addMouseListener(this);
  68.    }
  69.  
  70.    public void register() {
  71.       try {
  72.          URL u = new URL("http://www.taijisoftware.com");
  73.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  74.       } catch (Exception e) {
  75.          System.out.println(e);
  76.          this.stop();
  77.       }
  78.    }
  79.  
  80.    public void init() {
  81.       String codeBase = null;
  82.  
  83.       try {
  84.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  85.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  86.          codeBase = codeBase.toUpperCase();
  87.       } catch (Exception var9) {
  88.       }
  89.  
  90.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  91.          String regCode = ((Applet)this).getParameter("registration_code");
  92.          if (regCode == null) {
  93.             regCode = ((Applet)this).getParameter("reg_domain");
  94.             if (regCode == null) {
  95.                this.register();
  96.             } else {
  97.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  98.                   codeBase = "WWW." + codeBase;
  99.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  100.                   codeBase = codeBase.substring(4);
  101.                }
  102.  
  103.                char[] chars = new char[codeBase.length()];
  104.                codeBase.getChars(0, codeBase.length(), chars, 0);
  105.                String key = new String("haricot");
  106.                char[] chars2 = new char[key.length()];
  107.                key.getChars(0, key.length(), chars2, 0);
  108.  
  109.                for(int i = 0; i < codeBase.length(); ++i) {
  110.                   int j;
  111.                   if (i >= key.length()) {
  112.                      j = i - key.length() * (i / key.length());
  113.                   } else {
  114.                      j = i;
  115.                   }
  116.  
  117.                   chars[i] += chars2[j];
  118.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  119.                }
  120.  
  121.                String res = new String(chars);
  122.                if (!res.equalsIgnoreCase(regCode)) {
  123.                   this.register();
  124.                }
  125.             }
  126.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  127.             this.register();
  128.          }
  129.       }
  130.  
  131.       this.getParameters();
  132.       if (this.sound != null) {
  133.          if (this.loopSound) {
  134.             this.sound.loop();
  135.             return;
  136.          }
  137.  
  138.          this.sound.play();
  139.       }
  140.  
  141.    }
  142.  
  143.    public void getParameters() {
  144.       this.field_2 = ((Component)this).getSize().width;
  145.       this.field_3 = ((Component)this).getSize().height;
  146.       String s = ((Applet)this).getParameter("pause");
  147.       if (s != null) {
  148.          this.pause = Integer.parseInt(s);
  149.       }
  150.  
  151.       s = ((Applet)this).getParameter("r_lim");
  152.       if (s != null) {
  153.          this.r_lim = Integer.parseInt(s);
  154.       }
  155.  
  156.       s = ((Applet)this).getParameter("r_step");
  157.       if (s != null) {
  158.          this.r_step = Integer.parseInt(s);
  159.       }
  160.  
  161.       this.image_string = ((Applet)this).getParameter("image");
  162.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  163.       s = ((Applet)this).getParameter("sound_name");
  164.       if (s != null) {
  165.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  166.       }
  167.  
  168.       s = ((Applet)this).getParameter("loop_sound");
  169.       if (s != null) {
  170.          if (s.equals("yes")) {
  171.             this.loopSound = true;
  172.          } else {
  173.             this.loopSound = false;
  174.          }
  175.       }
  176.  
  177.       s = ((Applet)this).getParameter("clic_sound_name");
  178.       if (s != null) {
  179.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  180.       }
  181.  
  182.       s = ((Applet)this).getParameter("enter_sound_name");
  183.       if (s != null) {
  184.          this.enterSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  185.       }
  186.  
  187.       this.link = ((Applet)this).getParameter("link");
  188.       this.enterText = ((Applet)this).getParameter("enter_text");
  189.       s = ((Applet)this).getParameter("enter_text_height");
  190.       if (s != null) {
  191.          this.enterTextHeight = Integer.parseInt(s);
  192.       }
  193.  
  194.       this.enterTextColor = this.getColor("enter_text_color");
  195.       if (this.enterTextColor == null) {
  196.          this.enterTextColor = Color.white;
  197.       }
  198.  
  199.    }
  200.  
  201.    public Color getColor(String param) {
  202.       String s = ((Applet)this).getParameter(param);
  203.       if (s != null) {
  204.          if (s.substring(0, 1).equals("#")) {
  205.             s = s.substring(1);
  206.             int i = Integer.parseInt(s, 16);
  207.             return new Color(i);
  208.          } else {
  209.             return null;
  210.          }
  211.       } else {
  212.          return null;
  213.       }
  214.    }
  215.  
  216.    public void paint(Graphics g) {
  217.       if (this.loaded) {
  218.          this.field_0.clearRect(0, 0, this.field_2, this.field_3);
  219.          this.field_0.drawImage(this.image, 0, 0, this.field_2, this.field_3, this.field_4, this.field_5, this.field_4 + this.field_2, this.field_5 + this.field_3, this);
  220.          if (this.isEnterTextEnabled) {
  221.             this.field_0.drawString(this.enterText, (this.field_2 - this.wiEnterText) / 2, this.field_3 / 2);
  222.          }
  223.  
  224.          g.drawImage(this.buffer, 0, 0, this);
  225.       }
  226.  
  227.    }
  228.  
  229.    public void update(Graphics g) {
  230.       this.paint(g);
  231.    }
  232.  
  233.    public void start() {
  234.       if (this.thread == null) {
  235.          this.move = true;
  236.          this.thread = new Thread(this);
  237.          this.thread.start();
  238.       }
  239.  
  240.    }
  241.  
  242.    public void stop() {
  243.       if (this.thread != null) {
  244.          this.move = false;
  245.          this.thread = null;
  246.       }
  247.  
  248.       if (this.sound != null) {
  249.          this.sound.stop();
  250.       }
  251.  
  252.    }
  253.  
  254.    public void run() {
  255.       if (!this.loaded) {
  256.          MediaTracker tracker = new MediaTracker(this);
  257.          this.image = ((Applet)this).getImage(((Applet)this).getCodeBase(), this.image_string);
  258.          tracker.addImage(this.image, 0);
  259.  
  260.          try {
  261.             tracker.waitForAll();
  262.             this.loaded = !tracker.isErrorAny();
  263.          } catch (Exception e) {
  264.             System.out.println(e);
  265.          }
  266.  
  267.          if (!this.loaded) {
  268.             this.stop();
  269.          }
  270.       }
  271.  
  272.       this.wi_im = this.image.getWidth(this);
  273.       this.he_im = this.image.getHeight(this);
  274.       this.buffer = ((Component)this).createImage(this.field_2, this.field_3);
  275.       this.field_0 = this.buffer.getGraphics();
  276.       this.field_0.setColor(this.enterTextColor);
  277.       String fontName = ((Applet)this).getParameter("enter_text_font");
  278.       if (fontName == null) {
  279.          fontName = "TimesRoman";
  280.       }
  281.  
  282.       int style = 1;
  283.       String s = ((Applet)this).getParameter("enter_text_style");
  284.       if (s != null) {
  285.          if (s.equals("bold")) {
  286.             style = 1;
  287.          } else if (s.equals("italic")) {
  288.             style = 2;
  289.          } else if (s.equals("bold_italic")) {
  290.             style = 3;
  291.          } else {
  292.             style = 0;
  293.          }
  294.       }
  295.  
  296.       this.field_0.setFont(new Font(fontName, style, this.enterTextHeight));
  297.       this.field_7 = this.field_0.getFontMetrics();
  298.       if (this.enterText != null) {
  299.          this.wiEnterText = this.field_7.stringWidth(this.enterText);
  300.       }
  301.  
  302.       int X_last = 0;
  303.       int Y_last = 0;
  304.  
  305.       while(this.move) {
  306.          while(this.field_1) {
  307.             this.phi = (double)((int)((double)360.0F * Math.random()));
  308.             this.field_6 = 0;
  309.             int r_max = (int)((double)(this.r_lim / 2) * Math.random()) + this.r_lim / 2;
  310.  
  311.             while(this.field_6 <= r_max) {
  312.                this.field_4 += (int)((double)this.r_step * Math.cos(this.phi / (double)180.0F * Math.PI));
  313.                this.field_5 += (int)((double)this.r_step * Math.sin(this.phi / (double)180.0F * Math.PI));
  314.                if (this.field_4 < 0 || this.field_5 < 0 || this.field_4 + this.field_2 > this.wi_im || this.field_5 + this.field_3 > this.he_im) {
  315.                   this.field_4 = X_last;
  316.                   this.field_5 = Y_last;
  317.                   break;
  318.                }
  319.  
  320.                X_last = this.field_4;
  321.                Y_last = this.field_5;
  322.                ((Component)this).repaint();
  323.  
  324.                try {
  325.                   Thread.sleep((long)this.pause);
  326.                } catch (InterruptedException var9) {
  327.                   this.stop();
  328.                }
  329.  
  330.                this.field_6 += this.r_step;
  331.                if (!this.field_1) {
  332.                   break;
  333.                }
  334.             }
  335.          }
  336.  
  337.          try {
  338.             Thread.sleep(100L);
  339.          } catch (InterruptedException var7) {
  340.             this.stop();
  341.          }
  342.       }
  343.  
  344.    }
  345.  
  346.    public URL giveURL(String url) {
  347.       try {
  348.          if (url.toUpperCase().startsWith("HTTP")) {
  349.             return new URL(url);
  350.          } else if (url.toUpperCase().startsWith("FTP")) {
  351.             int p = url.indexOf(":");
  352.             int p2 = url.indexOf(":", p + 1);
  353.             if (p2 != -1) {
  354.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  355.             }
  356.  
  357.             p = url.indexOf("%40");
  358.             if (p != -1) {
  359.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  360.             }
  361.  
  362.             return new URL(url);
  363.          } else {
  364.             return new URL(((Applet)this).getCodeBase(), url);
  365.          }
  366.       } catch (MalformedURLException e) {
  367.          System.out.println(e);
  368.          return null;
  369.       }
  370.    }
  371.  
  372.    public void mouseClicked(MouseEvent e) {
  373.    }
  374.  
  375.    public void mouseEntered(MouseEvent e) {
  376.       if (this.enterText != null) {
  377.          this.isEnterTextEnabled = true;
  378.          ((Component)this).repaint();
  379.       }
  380.  
  381.       if (this.statusBarText != null) {
  382.          ((Applet)this).showStatus(this.statusBarText);
  383.       }
  384.  
  385.       if (this.enterSound != null) {
  386.          this.enterSound.play();
  387.       }
  388.  
  389.       if (this.link != null) {
  390.          ((Component)this).setCursor(new Cursor(12));
  391.       }
  392.  
  393.    }
  394.  
  395.    public void mouseExited(MouseEvent e) {
  396.       if (this.isEnterTextEnabled) {
  397.          this.isEnterTextEnabled = false;
  398.          ((Component)this).repaint();
  399.       }
  400.  
  401.       if (this.link != null) {
  402.          ((Component)this).setCursor(new Cursor(0));
  403.       }
  404.  
  405.    }
  406.  
  407.    public void mousePressed(MouseEvent e) {
  408.       if (this.clicSound != null) {
  409.          this.clicSound.play();
  410.       }
  411.  
  412.       if (this.link != null) {
  413.          String target = ((Applet)this).getParameter("target");
  414.          if (target == null) {
  415.             target = "_blank";
  416.          }
  417.  
  418.          URL u = this.giveURL(this.link);
  419.          ((Applet)this).getAppletContext().showDocument(u, target);
  420.       }
  421.  
  422.    }
  423.  
  424.    public void mouseReleased(MouseEvent e) {
  425.    }
  426. }
  427.